package com.shaw.mybatisx.proxy;

import com.shaw.mybatisx.session.Configuration;
import com.shaw.mybatisx.session.SqlSession;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by asus on 2018/4/1.
 */
public class MapperProxy implements InvocationHandler {
    private Class target;
    private SqlSession sqlSession;

    public MapperProxy(Class clazz,SqlSession sqlSession) {
        this.target = clazz;
        this.sqlSession = sqlSession;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Configuration.MapperDate mapperDate = Configuration.registMap.get(method.getDeclaringClass().getName()+"."+method.getName());
        if("select".equals(mapperDate.getSqlType())){
            return sqlSession.selectOne(mapperDate,args[0]);
        }else  if("insert".equals(mapperDate.getSqlType())){

        }
        return null;
    }
}
